// pages/luoAn/my/device/deviceInfo.js

const app = getApp()
const {LuoAnHttp} = app.globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataSource:[],
    pagesize:10,
    pagecurrent:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadDeviceList({pagesize:10,pagecurrent:1})
  },
  loadDeviceList:async function(param = {pagesize:10,pagecurrent:1}){
    const deviceList = await LuoAnHttp.asyncGetDeviceList(param)      
    if(deviceList&&deviceList.data){

      this.setData({
        dataSource:param.pagecurrent==1?[].concat(deviceList.data.records):this.data.dataSource.concat(deviceList.data.records) ,
        pagecurrent:param.pagecurrent
      })
    }
  },

  onClick: function(e){
    const model = e.detail;
    wx.showModal({
      title:"提示",
      content:"是否确定删除此设备",
      showCancel:true,
      confirmColor:"#0F93F2",
      success:async res=>{
        if (res.confirm) {
          const data = await LuoAnHttp.asyncDeleteDevice({eqid:model.eqid});
          
          if(data){
            this.loadDeviceList({pagesize:10,pagecurrent:1})
          }
        } else if (res.cancel) {

        }
      }
    })




    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.loadDeviceList({pagesize:10,pagecurrent:1})
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadDeviceList({pagesize:this.data.pagesize,pagecurrent:1+this.data.pagecurrent})
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  popMethod:function(e){
    let pages = getCurrentPages();
    if(pages.length>1){
      wx.navigateBack();
    }else{
      wx.reLaunch({
        url: '/pages/luoAn/device/deviceIndex',
      })
    }
  }
})